<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('定制管理')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>机构名称：</label>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <label>机构ID：</label>
                            <input type="text" name="id"/>
                        </li>

                        <li>
                            <label>机构类型：</label>
                            <div class="col-sm-2">
                                <select class="form-control" name="infoType">
                                    <option value="">所有</option>
                                    <option th:each="item:${infoTypeList}" th:value="${item.value}" th:text="${item.name}"></option>
                                </select>
                            </div>
                        </li>
<!--                        <li>-->
<!--                            <label>风控前置：</label>-->
<!--                            <div class="col-sm-2">-->
<!--                                <select class="form-control" name="riskFlag">-->
<!--                                    <option value="">所有</option>-->
<!--                                    <option value="1">有风控</option>-->
<!--                                    <option value="0">无风控</option>-->
<!--                                </select>-->
<!--                            </div>-->
<!--                        </li>-->
                        <li>
                            <label>客户经理：</label>
                            <div class="col-sm-2">
                                <select class="form-control" name="ownerUserId">
                                    <option value="">所有</option>
                                    <option th:each="item:${managerInfoList}" th:value="${item.userId}" th:text="${item.username}"></option>
                                </select>
                            </div>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="special:info:add">
                <i class="fa fa-plus"></i> 机构开户
            </a>
            <a class="btn btn-primary" onclick="managerInfoList();" shiro:hasPermission="special:managerInfo:view">
                客户经理
            </a>
            <!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="special:info:remove">-->
            <!--                    <i class="fa fa-remove"></i> 删除-->
            <!--                </a>-->
            <!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="special:info:export">-->
            <!--                    <i class="fa fa-download"></i> 导出-->
            <!--                </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="specialInfoTable"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">

    var editFlag = [[${@permission.hasPermi('special:info:edit')}]];
    var removeFlag = [[${@permission.hasPermi('special:info:remove')}]];
    var prefix = ctx + "special/info";

    $(function () {
        var options = {
            id: 'specialInfoTable',
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "机构信息",
            rowStyle: function (row, index) {   // 动态修改行的颜色
                // 注意：即使不改变颜色，也得返回 '' ，否则会报错。
                var result = '';
                if (row.status == 1) {
                    if (row.infoType == 'CRM') {
                        result = {css: {"background-color": "rgba(113,194,99,0.5)"}};
                    } else {
                        result = {css: {"background-color": "rgba(163,231,151,0.5)"}};
                    }
                }
                return result;
            },
            columns: [
                {
                    field: 'id',
                    title: '机构ID',
                },
                {
                    field: 'name',
                    title: '机构名称',
                    formatter: function (value, row, index) {
                        // var result = row.infoType;
                        // if (row.infoType == 'CRM') {
                        //     result = '<span style="color: #1c84c6;" >' + row.infoType + '</span>';
                        // } else if (row.infoType == 'API') {
                        //     result = '<span style="color: #c90e46;" >' + row.infoType + '</span>';
                        // }
                        var name = '<span style="color: green;">' + row.name + '</span>';
                        // result = name + ' [' + result + '] '

                        var onClickFunction = 'List(\'' + row.id + '\')';
                        return '<span onclick="' + onClickFunction + '">' + name + '</span>';
                    }

                },
                {
                    field: 'descInfo',
                    title: '对接类型',
                    formatter: function (value, row, index) {
                        return row.infoTypeStr + '【' + row.infoType + '】'
                    }
                },
                {
                    field: 'descInfo',
                    title: '价格类型/分润比例',
                    formatter: function (value, row, index) {
                        return row.priceTypeStr + '【' + row.typeRate + '】'
                    }
                },
                {
                    field: 'descInfo',
                    title: '描述'
                },
                {
                    field: 'ownerUsername',
                    title: '客户经理',
                    formatter: function (value, row, index) {
                        return row.ownerUsername + '【' + row.ownerUserId + '】'
                    }
                },
                {
                    field: 'remainAmount',
                    title: '余额',
                    formatter: function (value, row, index) {
                        var result = row.avaliableAmount;
                        if (result <= 200 && row.status == 1) {
                            result = '<span style="color: #c90e46;" >' + result + '</a>';
                        }
                        return result
                    }
                },
                {
                    field: 'adminAccount',
                    title: '登陆账号',
                    formatter: function (value, row, index) {
                        if (row.adminAccount == undefined || row.adminAccount == '') {
                            return '-';
                        }
                        return '<span style="color: darkgreen; border-bottom: 1px solid" onclick="showAccount(\'' + row.name + '\' , \'' + row.adminAccount + '\' , \'' + row.adminPwd + '\' )">展示</span>'
                    }
                },
                {
                    field: 'baseInfo',
                    title: '机构信息',
                    formatter: function (value, row, index) {
                        return '<span style="color: darkgreen; border-bottom: 1px solid" onclick="showCompanyInfo('
                            + '\'' + row.companyName
                            + '\', \'' + row.companyLogo
                            + '\', \'' + row.productName
                            + '\', \'' + row.maxLoanAmount
                            + '\', \'' + row.maxRate
                            + '\',\'' + row.minRate + '\' )">展示</span>'
                    }
                },
                {
                    field: 'onlineInfo',
                    title: '在线信息'
                },
                {
                    field: '',
                    title: '成功量 / 目标量',
                    formatter: function (value, row) {
                        var pushNumber = row.pushNumber || 0;
                        var successNumber = row.Number || 0;
                        return '<span>' + '<span style="color: red;">' + successNumber + '</span>' + ' / ' + pushNumber + '</span>';
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: '',
                    title: '任务',
                    formatter: function (value, row, index) {
                        return '<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="itemInfoList(\'' + row.id + '\', \'' + row.name + '\')">任务</a>';
                    }
                },
                {
                    field: 'onlineInfo',
                    title: '数据',
                    formatter: function (value, row, index) {
                        if (row.infoType == 'CRM') {
                            return '<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="detailCrm(\'' + row.id + '\' , \'' + row.name + '\')"><i class="fa fa-list-ul"></i>数据</a> ';
                        } else if (row.infoType == 'API') {
                            return '<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="detailApi(\'' + row.id + '\' , \'' + row.name + '\')"><i class="fa fa-list-ul"></i>数据</a> ';
                        }
                    }
                },
                {
                    field: 'onlineInfo',
                    title: '成员',
                    formatter: function (value, row, index) {
                        if (row.infoType == 'CRM') {
                            return '<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="memberList(\'' + row.id + '\', \'' + row.name + '\')"><i class="fa fa-list-ul"></i>成员</a> '
                        }
                        return '-';
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);


        console.log("页面显示了。。。。。。")
    });

    console.log("页面显示了。。。。。。111111")

    /* 用户状态显示 */
    function statusTools(row) {
        if (row.status == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 用户管理-停用 */
    function disable(id) {
        $.modal.confirm("确认要停用吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "status": 0});
        })
    }

    /* 用户管理启用 */
    function enable(id) {
        $.modal.confirm("确认要启用吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "status": 1});
        })
    }

    /*字典列表-详细*/
    function detailCrm(infoId, name) {
        var url = ctx + 'special/data/' + infoId;
        $.modal.openTab(name + "-数据列表", url);
    }

    /*字典列表-详细*/
    function detailApi(infoId, name) {
        var url = ctx + 'special/apiData/item/' + infoId;
        $.modal.openTab(name + "-数据列表", url);
    }

    /*字典列表-详细*/
    function memberList(costomId, costomName) {
        var url = ctx + 'special/costomuser/' + costomId;
        $.modal.openTab(costomName + "—成员列表", url);
    }

    /***
     * 任务列表
     * @param costomId
     */
    function itemInfoList(costomId, costomName) {
        var url = ctx + 'special/itemInfo/' + costomId;
        $.modal.openTab(costomName + '-任务列表', url);
    }

    function showAccount(name, account, pwd) {
        var content =
            '账户：' + name +
            '<br>账号：' + account +
            '<br>密码：' + pwd +
            '<br>登陆地址：https://admin.goldenblossom.cn'
        $.modal.alert(content, modal_status.MESSAGE, '账号信息');
    }

    function showCompanyInfo(companyName, companyLogo, productName, maxLoanAmount, maxRate, minRate ) {
        var content =
            '公司名称：' + companyName +
            // '<br>公司logo：' + companyLogo +
            '<br>公司logo：' + ' <img  width="90px" height="60px"  src="'+companyLogo+'">' +
            '<br>产品名称：' + productName +
            '<br>最大贷款金额：' + maxLoanAmount +
            '<br>最大利率：' + maxRate +
            '<br>最大利率：' + minRate
        $.modal.alert(content, modal_status.MESSAGE, '机构信息信息');
    }

    function managerInfoList() {
        var url = ctx + 'special/managerInfo/1';
        $.modal.openTab('客户经理', url);
    }

    /**
     * 操作日志
     * @param Id
     * @param channelName
     * @constructor
     */
    function List(Id) {
        var url = ctx + 'special/operatorlog/' + Id;
        $.modal.openTab('操作记录', url);
    }

</script>
</body>
</html>